home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CreateObject.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __CREATEOBJECT__
- #define __CREATEOBJECT__
-
- #ifndef __TYPES__
- #include "Types.h"
- #endif
-
- /***********************************|****************************************/
-
- // this is the formal C++ type for our default constructor
- typedef void* (*Constructor) ( void* );
-
- // this is the public interface to creating an object by string name
- extern void* CreateObject ( const char* className );
-
- /*============================================================================
-
- TDefaultConstructorIterator is a class which allows a convenient
- programmatic interface to access and iterate over the contents of a
- 'FcAd' resource. If the default constructor is used, the class will
- attempt to load the 'FcAd' resource from the currrent application
- resource fork by itself. You can also pass in an existing 'FcAd' handle.
-
- The following is an example of TDefaultConstructorIterator use:
-
- {
- TDefaultConstructorIterator iterator; // best to create object on stack
- const char* const kDesiredName = "__ct__TExampleClassFv";
- const char* currentName;
-
- for ( currentName = iterator.FirstConstructor ();
- currentName != nil;
- currentName = iterator.NextConstructor () )
- {
- if ( strcmp ( desiredName, currentName ) == 0 )
- return iterator.GetAddress (); // we found the one we want! :)
- }
-
- return nil; // we did not find the one we want :(
- }
-
- ----------------------------------------------------------------------------*/
-
- class TDefaultConstructorIterator
- {
- public:
- TDefaultConstructorIterator ();
- TDefaultConstructorIterator ( const Handle ctLU );
- ~TDefaultConstructorIterator ();
-
- // use these to iterate over the entries
-
- const char* FirstConstructor (); // might return nil
- const char* NextConstructor (); // will return nill when done
-
- // these are only valid for currrent FirstEntry or NextEntry
-
- const Constructor GetConstructorAddress () const;
- short GetConstructorResourceID () const;
- unsigned long GetConstructorOffset () const;
-
- protected:
-
- static const OSType kCodeResourceType;
- static const OSType kLookupResourceType;
- static const short kLookupResourceID;
-
- private:
- Handle GetLookupResource ();
- void SetupLookupResource ( Handle );
-
- Handle fResource;
- SignedByte fState;
- char* fMaxName;
- char* fCurrentName;
- short fID;
- unsigned long fOffset;
- };
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- #pragma push
- #pragma segment CreateObject
-
- inline short
- TDefaultConstructorIterator::GetConstructorResourceID () const
- {
- return fID;
- }
-
- /***********************************|****************************************/
-
- inline unsigned long
- TDefaultConstructorIterator::GetConstructorOffset () const
- {
- return fOffset;
- }
-
- #pragma pop
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- #endif // __CREATEOBJECT__
-